package com.cj.springmvc.test.dto;

import java.io.Serializable;

import javax.validation.constraints.NotNull;
import javax.validation.constraints.Pattern;
import javax.validation.constraints.Size;


/**
 * <b>JSR-303 Bean Validation API </b>defines a set of constraints in the form of<br/>
 * Java annotations under the package </b>javax.validation.constraints</b> that can be <br/>
 * applied to the domain objects.Here we applied it to dto.In addition <br/>
 * custom validators (class-level) can be developed and applied using annotations.<br/>
 * Project:<b> Hibernate Validator</b> (http://hibernate.org/subprojects/validator)
 * @author cj
 *
 */
public class PersonsDto implements Serializable{
	/**
	 * 
	 */
	private static final long serialVersionUID = -4532260924169040221L;
	private Long id;
	@NotNull
	@Size(min=3, max=20,message ="用户名长度必须大于3小于20")
	@Pattern(regexp="^[a-zA-Z0-9]+$",
			message="用户名必须为字母数字并且不包含空格")
	private String username;
	@NotNull
	@Size(min = 4,max = 16,message = "密码必须在4~16位之间")
	private String password;
	@NotNull
	@Pattern(regexp ="[_A-Za-z0-9-]+(\\.[_A-Za-z0-9-]+)*@[A-Za-z0-9]+(\\.[A-Za-z0-9]+)*(\\.[A-Za-z]{2,})",
			message = "邮箱格式不正确")
	private String email;
	private String authority;
	public Long getId() {
		return id;
	}
	public void setId(Long id) {
		this.id = id;
	}
	public String getUsername() {
		return username;
	}
	public void setUsername(String username) {
		this.username = username;
	}
	public String getPassword() {
		return password;
	}
	public void setPassword(String password) {
		this.password = password;
	}
	public String getEmail() {
		return email;
	}
	public void setEmail(String email) {
		this.email = email;
	}
	
	public String getAuthority() {
		return authority;
	}
	public void setAuthority(String authority) {
		this.authority = authority;
	}
	
	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result
				+ ((authority == null) ? 0 : authority.hashCode());
		result = prime * result + ((email == null) ? 0 : email.hashCode());
		result = prime * result + ((id == null) ? 0 : id.hashCode());
		result = prime * result
				+ ((password == null) ? 0 : password.hashCode());
		result = prime * result
				+ ((username == null) ? 0 : username.hashCode());
		return result;
	}
	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		PersonsDto other = (PersonsDto) obj;
		if (authority == null) {
			if (other.authority != null)
				return false;
		} else if (!authority.equals(other.authority))
			return false;
		if (email == null) {
			if (other.email != null)
				return false;
		} else if (!email.equals(other.email))
			return false;
		if (id == null) {
			if (other.id != null)
				return false;
		} else if (!id.equals(other.id))
			return false;
		if (password == null) {
			if (other.password != null)
				return false;
		} else if (!password.equals(other.password))
			return false;
		if (username == null) {
			if (other.username != null)
				return false;
		} else if (!username.equals(other.username))
			return false;
		return true;
	}
	@Override
	public String toString() {
		return "PersonsDto [id=" + id + ", username=" + username
				+ ", password=" + password + "]";
	}
	
}
